<template>
  <div>
    <el-main>
      <div style="font-size: 16px;padding-bottom: 10px;border-bottom: 1px solid #eee;margin-bottom: 15px;">
        <span style="display: inline-block;padding-left: 10px;border-left: 4px solid #1890ff;">基本信息</span> <span style="font-size: 14px;">（带"<span style="color: red;">*</span>"为必填项）</span>
      </div>

      <div style="display: flex;">
        <div style="margin-top: 7px;width: 100px;text-align: right;"><span style="color: red;">*</span>采购员编号：</div>
        <div style="width: 400px">
          <el-input  placeholder="长度＜10,必填项" v-model="code">

          </el-input>
        </div>
      </div>

      <div style="display: flex;margin-top: 20px;">
        <div style="margin-top: 7px;width: 100px;text-align: right;"><span style="color: red;">*</span>采购员名称：</div>
        <div style="width: 400px">
          <el-input  placeholder="长度＜10,必填项" v-model="name">
          </el-input>
        </div>
      </div>

      <div style="display: flex;margin-top: 20px;">
        <div style="margin-top: 7px;width: 100px;text-align: right;"><span style="color: red;">*</span>手机号：</div>
        <div style="width: 400px">
          <el-input  placeholder="输入手机号" v-model="phone">

          </el-input>
        </div>
      </div>
      <div style="margin:50px 0 0 100px;">
          <el-button type="primary"  @click="addfunc" >保存</el-button>
          <el-button @click="funcback">取消</el-button>
      </div>
    </el-main>
  </div>
</template>

<script>
  import { handleActivePath } from '@/utils/routes'
  import { mapActions } from 'vuex'
  import {addbuyer} from '@/api/purchase/buyerapi'
  export default{
    data(){
      return {
        name:"",//名字
        phone:"",//手机号码
        code:"",//密码
        password:"",//密码
      }
    }
    ,methods:{
      ...mapActions({
        delVisitedRoute: 'tabs/delVisitedRoute',
      }),
      funcback(){
        this.$confirm('确定返回列表页面?', '确定', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning',
        })
          .then(async () => {
            const detailPath = await handleActivePath(this.$route, true)
            await this.$router.push('/purchase/initialvalue/buyer')
            await this.delVisitedRoute(detailPath)
          })
          .catch(() => {})
      },
      async addfunc(){
        if(this.name =="" || this.phone == "" || this.phone.length != 11 || this.code=="" || this.name.length>10){
          this.$message.error('请正确填写信息');
          return
        }
        let data={
          name:this.name,
          phone:this.phone,
          code:this.code,
          sysId:28
        }
        let ress =  await addbuyer(data)
        if(ress.status == 200){
          this.$router.push("/purchase/initialvalue/buyer")
          this.$message('添加成功');
        }else{
          this.$message.error('提交错误');
        }
      }
    }
  }
</script>

<style>
</style>
